//
//  RootViewController.m
//  UI18_数据库
//
//  Created by dllo on 15/12/2.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"
#import "DataBaseHandle.h"
#import "Student.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor whiteColor];
    NSLog(@"%@", NSHomeDirectory());
    
    
    
    
    
    
    
}

// 打开数据库
- (IBAction)openAction:(UIButton *)sender {
    [[DataBaseHandle shareDataBase] openDB];
}

// 关闭数据库
- (IBAction)closeAction:(id)sender {
    [[DataBaseHandle shareDataBase] closeDB];
}

// 创建表单
- (IBAction)createAction:(id)sender {
    [[DataBaseHandle shareDataBase] createTable];
}

// 删除表单
- (IBAction)deleteAction:(id)sender {
    [[DataBaseHandle shareDataBase] deleteTable];
}

// 插入数据
- (IBAction)insertDataAction:(id)sender {
    Student *stu = [[Student alloc] init];
    stu.name = @"王宁";
    stu.sex = @"男";
    stu.age = 50;
    [[DataBaseHandle shareDataBase] insertDataWithStudent:stu];
}

// 修改数据
- (IBAction)updataAction:(id)sender {
    Student *stu = [[Student alloc] init];
    stu.name = @"李四";
    stu.sex = @"女";
    stu.age = 26;
    
    [[DataBaseHandle shareDataBase] updateDataWithStudent:stu Number:4];
    
}

// 删除数据
- (IBAction)deleteDateAction:(UIButton *)sender {
    [[DataBaseHandle shareDataBase] deleteDataWithNumber:2];
}
- (IBAction)selectAllAction:(id)sender {
    NSMutableArray *stuArr = [[DataBaseHandle shareDataBase] selectAllStudent];
    for (Student *stu in stuArr) {
        NSLog(@"%@ %@ %ld", stu.name, stu.sex, stu.age);
    }
}
- (IBAction)selectByClassifyAction:(id)sender {
    NSMutableArray *stuArr = [[DataBaseHandle shareDataBase] selectBysex:@"女"];
    for (Student *stu in stuArr) {
        NSLog(@"%@ %@ %ld", stu.name, stu.sex, stu.age);
    }
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
